package com.yiren.dbaa.module.project_edit.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiren.backstage.currency.entity.LineInfoEntity;
import com.yiren.backstage.currency.entity.ProjectEntity;
import com.yiren.dbaa.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 随机线路选择适配器
 */
public class RandomLineAdapter extends BaseAdapter {

    private Context context;
    /*** 可选的线路集合 */
    private List<LineInfoEntity> lines;
    /*** 已选的线路集合 */
    private List<String> selectedLines;

    public RandomLineAdapter(Context context, List<LineInfoEntity> lines, List<String> selectedLines) {
        this.context = context;
        this.lines = lines;
        this.selectedLines = selectedLines;
    }

    @Override
    public int getCount() {
        return lines.size();
    }

    @Override
    public Object getItem(int arg0) {
        return lines.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_select_param, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvTitle.setText(lines.get(position).getName());
        if (selectedLines.contains(lines.get(position).getId())) {
            holder.ivStatus.setImageResource(R.mipmap.dbaf_start_light_on);
        } else {
            holder.ivStatus.setImageResource(R.mipmap.dbaf_start_light_off);
        }
        return convertView;
    }

    public class ViewHolder {
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.iv_status)
        ImageView ivStatus;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
